package org.hqs.clinic.controller;

import com.fasterxml.jackson.databind.annotation.JsonNaming;
import org.hqs.clinic.common.JsonResult;
import org.hqs.clinic.pojo.Clinic;
import org.hqs.clinic.service.ClinicService;
import org.hqs.feign.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clinic")
public class ClinicController {
    @Autowired
    private ClinicService clinicService;

    @GetMapping("/{orderId}")
    public JsonResult<Clinic>  queryClinicById(@PathVariable("orderId") Long orderId) {
        return new JsonResult(clinicService.queryClinicById(orderId));
    }

    @GetMapping("/all")
    public JsonResult<List<Clinic>> getAllClinics() {
        return new JsonResult(clinicService.findAllClinics()) ;
    }

    @PostMapping("/add")
    public JsonResult addClinic(@RequestBody Clinic clinic) {
        int result = clinicService.addClinic(clinic);
        return result > 0 ? new JsonResult<>("200", "添加成功") : new JsonResult<>("400", "添加失败");
    }

    @PutMapping("/update")
    public JsonResult updateClinic(@RequestBody Clinic clinic) {
        int result = clinicService.updateClinic(clinic);
        return result > 0 ? new JsonResult<>("200", "修改成功") : new JsonResult<>("400", "修改失败");
    }

    @DeleteMapping("/delete/{clinicId}")
    public JsonResult deleteClinic(@PathVariable("clinicId") Long clinicId) {
        int result = clinicService.deleteClinicById(clinicId);
        return result > 0 ? new JsonResult<>("200", "删除成功") : new JsonResult<>("400", "删除失败");
    }

    @GetMapping("/find_by_department_id/{departmentId}")
    public JsonResult<List<Clinic>> findClinicByDepartmentId(@PathVariable("departmentId") Long departmentId) {
        return new JsonResult(clinicService.findClinicByDepartmentId(departmentId));
    }

}
